﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Himp.Platform.Dc.Migrations
{
    /// <inheritdoc />
    public partial class addtablePUB_ITEM : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AlterColumn<DateTime>(
                name: "LastModificationTime",
                schema: "Dc",
                table: "STD_PHR_DICT",
                type: "timestamp without time zone",
                nullable: true,
                oldClrType: typeof(DateTime),
                oldType: "timestamp with time zone",
                oldNullable: true);

            migrationBuilder.AlterColumn<DateTime>(
                name: "CreationTime",
                schema: "Dc",
                table: "STD_PHR_DICT",
                type: "timestamp without time zone",
                nullable: false,
                oldClrType: typeof(DateTime),
                oldType: "timestamp with time zone");

            migrationBuilder.AlterColumn<DateTime>(
                name: "CHK_TIME",
                schema: "Dc",
                table: "SPLER_DICT",
                type: "timestamp without time zone",
                nullable: true,
                oldClrType: typeof(DateTime),
                oldType: "timestamp with time zone",
                oldNullable: true);

            migrationBuilder.CreateTable(
                name: "PUB_ITEM",
                schema: "Dc",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    PubItemTypeId = table.Column<Guid>(type: "uuid", nullable: false),
                    DefChrgitmTypeId = table.Column<Guid>(type: "uuid", nullable: false),
                    PUB_ITEM_CODG = table.Column<string>(type: "text", nullable: false),
                    PUB_ITEM_NAME = table.Column<string>(type: "text", nullable: false),
                    SPEC = table.Column<string>(type: "text", nullable: false),
                    UNT = table.Column<string>(type: "text", nullable: false),
                    PRIC = table.Column<decimal>(type: "numeric", nullable: false),
                    PINYINCODE = table.Column<string>(type: "text", nullable: true),
                    WUBICODE = table.Column<string>(type: "text", nullable: true),
                    PRICE_CODE = table.Column<string>(type: "text", nullable: true),
                    CHK_FLAG = table.Column<bool>(type: "boolean", nullable: false),
                    DISAB_FLAG = table.Column<bool>(type: "boolean", nullable: false),
                    SRT_NO = table.Column<int>(type: "integer", nullable: false),
                    AGMT_ITEM_FLAG = table.Column<bool>(type: "boolean", nullable: false),
                    DETL_ITEM_ID = table.Column<Guid>(type: "uuid", nullable: true),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true),
                    ExtraProperties = table.Column<string>(type: "text", nullable: false),
                    ConcurrencyStamp = table.Column<string>(type: "character varying(40)", maxLength: 40, nullable: false),
                    CreationTime = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uuid", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "timestamp without time zone", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uuid", nullable: true),
                    IsDeleted = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false),
                    DeleterId = table.Column<Guid>(type: "uuid", nullable: true),
                    DeletionTime = table.Column<DateTime>(type: "timestamp without time zone", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_PUB_ITEM", x => x.Id);
                    table.ForeignKey(
                        name: "FK_PUB_ITEM_CHRGITM_TYPE_DefChrgitmTypeId",
                        column: x => x.DefChrgitmTypeId,
                        principalSchema: "Dc",
                        principalTable: "CHRGITM_TYPE",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_PUB_ITEM_PUB_ITEM_TYPE_PubItemTypeId",
                        column: x => x.PubItemTypeId,
                        principalSchema: "Dc",
                        principalTable: "PUB_ITEM_TYPE",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "AGMT_ITEM",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    PubItemId = table.Column<Guid>(type: "uuid", nullable: false),
                    CNT = table.Column<float>(type: "real", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AGMT_ITEM", x => x.Id);
                    table.ForeignKey(
                        name: "FK_AGMT_ITEM_PUB_ITEM_PubItemId",
                        column: x => x.PubItemId,
                        principalSchema: "Dc",
                        principalTable: "PUB_ITEM",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "PUB_ITEM_ASSOC_BILG_DEPT",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    PubItemId = table.Column<Guid>(type: "uuid", nullable: false),
                    BILG_DEPT_CODG = table.Column<string>(type: "text", nullable: false),
                    BILG_DEPT_NAME = table.Column<string>(type: "text", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_PUB_ITEM_ASSOC_BILG_DEPT", x => x.Id);
                    table.ForeignKey(
                        name: "FK_PUB_ITEM_ASSOC_BILG_DEPT_PUB_ITEM_PubItemId",
                        column: x => x.PubItemId,
                        principalSchema: "Dc",
                        principalTable: "PUB_ITEM",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "PUB_ITEM_ASSOC_CHRGITM_TYPE",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    PubItemId = table.Column<Guid>(type: "uuid", nullable: false),
                    ChrgitmTypeId = table.Column<Guid>(type: "uuid", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_PUB_ITEM_ASSOC_CHRGITM_TYPE", x => x.Id);
                    table.ForeignKey(
                        name: "FK_PUB_ITEM_ASSOC_CHRGITM_TYPE_CHRGITM_TYPE_ChrgitmTypeId",
                        column: x => x.ChrgitmTypeId,
                        principalSchema: "Dc",
                        principalTable: "CHRGITM_TYPE",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_PUB_ITEM_ASSOC_CHRGITM_TYPE_PUB_ITEM_PubItemId",
                        column: x => x.PubItemId,
                        principalSchema: "Dc",
                        principalTable: "PUB_ITEM",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "PUB_ITEM_ASSOC_EXE_DEPT",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    PubItemId = table.Column<Guid>(type: "uuid", nullable: false),
                    EXE_DEPT_CODG = table.Column<string>(type: "text", nullable: false),
                    EXE_DEPT_NAME = table.Column<string>(type: "text", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_PUB_ITEM_ASSOC_EXE_DEPT", x => x.Id);
                    table.ForeignKey(
                        name: "FK_PUB_ITEM_ASSOC_EXE_DEPT_PUB_ITEM_PubItemId",
                        column: x => x.PubItemId,
                        principalSchema: "Dc",
                        principalTable: "PUB_ITEM",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_AGMT_ITEM_PubItemId",
                table: "AGMT_ITEM",
                column: "PubItemId");

            migrationBuilder.CreateIndex(
                name: "IX_PUB_ITEM_DefChrgitmTypeId",
                schema: "Dc",
                table: "PUB_ITEM",
                column: "DefChrgitmTypeId");

            migrationBuilder.CreateIndex(
                name: "IX_PUB_ITEM_PubItemTypeId",
                schema: "Dc",
                table: "PUB_ITEM",
                column: "PubItemTypeId");

            migrationBuilder.CreateIndex(
                name: "IX_PUB_ITEM_ASSOC_BILG_DEPT_PubItemId",
                table: "PUB_ITEM_ASSOC_BILG_DEPT",
                column: "PubItemId");

            migrationBuilder.CreateIndex(
                name: "IX_PUB_ITEM_ASSOC_CHRGITM_TYPE_ChrgitmTypeId",
                table: "PUB_ITEM_ASSOC_CHRGITM_TYPE",
                column: "ChrgitmTypeId");

            migrationBuilder.CreateIndex(
                name: "IX_PUB_ITEM_ASSOC_CHRGITM_TYPE_PubItemId",
                table: "PUB_ITEM_ASSOC_CHRGITM_TYPE",
                column: "PubItemId");

            migrationBuilder.CreateIndex(
                name: "IX_PUB_ITEM_ASSOC_EXE_DEPT_PubItemId",
                table: "PUB_ITEM_ASSOC_EXE_DEPT",
                column: "PubItemId");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "AGMT_ITEM");

            migrationBuilder.DropTable(
                name: "PUB_ITEM_ASSOC_BILG_DEPT");

            migrationBuilder.DropTable(
                name: "PUB_ITEM_ASSOC_CHRGITM_TYPE");

            migrationBuilder.DropTable(
                name: "PUB_ITEM_ASSOC_EXE_DEPT");

            migrationBuilder.DropTable(
                name: "PUB_ITEM",
                schema: "Dc");

            migrationBuilder.AlterColumn<DateTime>(
                name: "LastModificationTime",
                schema: "Dc",
                table: "STD_PHR_DICT",
                type: "timestamp with time zone",
                nullable: true,
                oldClrType: typeof(DateTime),
                oldType: "timestamp without time zone",
                oldNullable: true);

            migrationBuilder.AlterColumn<DateTime>(
                name: "CreationTime",
                schema: "Dc",
                table: "STD_PHR_DICT",
                type: "timestamp with time zone",
                nullable: false,
                oldClrType: typeof(DateTime),
                oldType: "timestamp without time zone");

            migrationBuilder.AlterColumn<DateTime>(
                name: "CHK_TIME",
                schema: "Dc",
                table: "SPLER_DICT",
                type: "timestamp with time zone",
                nullable: true,
                oldClrType: typeof(DateTime),
                oldType: "timestamp without time zone",
                oldNullable: true);
        }
    }
}
